#include <bits/stdc++.h>
// 2025/01/28
// tag: 
// Author: Zhang Muen
using namespace std;

int n, f[10][10][10][10], board[10][10];

int dfs(int x, int y, int x1, int y1){
    if (f[x][y][x1][y1] != 0)
        return f[x][y][x1][y1];
    if (x == n && y == n && x1 == n && y1 == n)
        return 0;
    int ans = 0;
    if (x < n && x1 < n)
        ans = max(ans, dfs(x + 1, y, x1 + 1, y1) + board[x + 1][y] + board[x1 + 1][y1] - bool(x == x1 && y == y1) * board[x + 1][y]);
    if (y < n && y1 < n)
        ans = max(ans, dfs(x, y + 1, x1, y1 + 1) + board[x][y + 1] + board[x1][y1 + 1] - bool(x == x1 && y == y1) * board[x][y + 1]);
    if (x < n && y1 < n)
        ans = max(ans, dfs(x + 1, y, x1, y1 + 1) + board[x + 1][y] + board[x1][y1 + 1] - bool(x + 1 == x1 && y == y1 + 1) * board[x1][y]);
    if (x1 < n && y < n)
        ans = max(ans, dfs(x, y + 1, x1 + 1, y1) + board[x][y + 1] + board[x1 + 1][y1] - bool(x == x1 + 1 && y1 == y + 1) * board[x][y1]);
    return f[x][y][x1][y1] = ans;
}

signed main()
{
    cin >> n;
    for (;;) {
        int x, y, v;
        cin >> x >> y >> v;
        if (x == 0 && y == 0 && v == 0)
            break;
        board[x][y] = v;
    }
    cout << dfs(1, 1, 1, 1) + board[1][1] << endl;
    return 0;
}